package com.jhy.suixianglu.daima20230113;

public class ReplaceSpace2 {
    public static  String replaceSpace(String s) {
        // 声明一个额外的字符串
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == ' '){
                builder.append("%20");
            }else {
                builder.append(s.charAt(i));
            }
        }
        return builder.toString();
    }

    public static void main(String[] args) {
        String s =  "We are happy.";
        String s1 = replaceSpace(s);
        System.out.println(s1);
    }
}
